You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces or adjusts the :filepath permalink pattern to replicate the previous behavior of :title, which was based on the post's file name and path under source/_posts/.
✅ What this PR does:
Restores old permalink behavior via :filepath
Enables backward compatibility for existing blogs without requiring manual changes to thousands of posts
Preserves legacy URLs and helps prevent SEO regressions or broken external links
🧪 How to test:
Add the following to your _config.yml:
permalink: :filepath/
Make sure your posts inside source/_posts/ generate the expected permalinks matching the file name.
This change helps long-time users maintain their blog structure and avoid unnecessary mass edits due to the breaking permalink change. Especially for blogger/wordpress users who have migrated to Hexo.
Thanks for working on a backward-compatible permalink option. I agree that a dedicated :filepath pattern is a reasonable approach, but I found a few issues that should be addressed before merging:
The new test imports Hexo from 'hexo'. The repository cannot resolve itself by package name in this context, so the test fails with TS2307: Cannot find module 'hexo'. Please use:
importHexofrom'../../../lib/hexo';
The implementation hard-codes the default source/ directory. With a custom configuration such as source_dir: content, _posts/nested/foo.md produces:
content/_posts/nested/foo.html
instead of:
nested/foo.html
Draft sources are not handled. _drafts/nested/foo.md currently produces _drafts/nested/foo.html, so the URL changes after the post is published.
Since Post.source already contains the path relative to source_dir, the implementation could be simplified to:
Please also add regression tests for a custom source_dir and an _drafts/ source. I tested this approach against the existing permalink tests plus those two cases, and all 22 related tests passed.
One more note: no GitHub Actions checks are currently reported for this PR, despite the CI checkbox being marked as completed. Rebasing onto the latest master should allow the current checks to run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does it do?
This PR introduces or adjusts the
:filepathpermalink pattern to replicate the previous behavior of:title, which was based on the post's file name and path undersource/_posts/.✅ What this PR does:
:filepath🧪 How to test:
_config.yml:source/_posts/generate the expected permalinks matching the file name.📌 Related Issue / Discussion:
Original issue and discussion
Issue describing permalink regression
🙏 Note:
This change helps long-time users maintain their blog structure and avoid unnecessary mass edits due to the breaking permalink change. Especially for blogger/wordpress users who have migrated to Hexo.
🔍 Test Results:
Dev repo (Hexo fork):
https://github.com/dimaslanjaka/hexo/tree/603a01549d895b60994e7b455574c5c915b4e35c
Test unit repo:
https://github.com/dimaslanjaka/hexo-theme-unit-test/tree/monorepo
Test result output (gh-pages):
https://github.com/dimaslanjaka/hexo-theme-unit-test/tree/gh-pages
Live site preview:
https://www.webmanajemen.com/hexo-theme-unit-test/
All posts render with the expected permalink structure using the
:filepathpattern.Issue resolved: #5658
Screenshots
Pull request tasks